/**
 * 药品库
 */
Lib = cc.Sprite.extend({
	libArr: [],
	openFlag:false,
	doing:false,
	rm : 5,
	ctor:function(p){
		this._super("#lib_back.png");
		p.addChild(this,30);
		this.setTag(TAG_LIB);
		this.init();
	},
	init:function(){
		this.libArr = [];
		this.openFlag = false;
		this.setPosition(gg.width + this.width * 0.5 + 9,550+30);

		var zilaishui = new LibButton(this, 10, TAG_LIB_ZILAISHUI,"#zilaishui.png", this.callback);
		zilaishui.setPosition(30, this.height * 0.5);

		var zhengliushui = new LibButton(this, 10, TAG_LIB_ZHENGLIUSHUI,"#zhengliushui.png", this.callback);
		zhengliushui.right(zilaishui, this.rm);
		
		var ironShelf = new LibButton(this, 10, TAG_LIB_IRON,"#ironShelf.png", this.callback);
		ironShelf.right(zhengliushui, this.rm);
		
		var ddg = new LibButton(this, 10, TAG_LIB_DDG,"#ddg.png", this.callback);
		ddg.right(ironShelf, this.rm);

		var xishuizhi =  new LibButton(this, 10, TAG_LIB_XISHUIZHI,"#xishuizhi.png", this.callback);
		xishuizhi.right(ddg, this.rm);
		  
		var beaker = new LibButton(this, 10, TAG_LIB_BEAKER,"#beaker/beaker.png", this.callback);
		beaker.right(xishuizhi, this.rm);

		var hcl = new LibButton(this, 10, TAG_LIB_HCL,"#xi.png", this.callback);
		hcl.right(beaker, this.rm);
		
		var yiyeguan =  new LibButton(this, 10, TAG_LIB_YIYEGUAN,"#yiyeguan.png", this.callback);
		yiyeguan.right(hcl, this.rm);
		
		var xierqiu =  new LibButton(this, 10, TAG_LIB_XIERQIU,"#xierqiu.png", this.callback);
		xierqiu.right(yiyeguan, this.rm);

		var jianye = new LibButton(this, 10, TAG_LIB_JIANYE,"#xi2.png", this.callback);
		jianye.right(xierqiu, this.rm);
		
		var zhui = new LibButton(this, 10, TAG_LIB_ZHUIXINGPING,"#zhuixingping.png", this.callback);
		zhui.right(jianye, this.rm);
		
		var fentai = new LibButton(this, 10, TAG_LIB_FENTAI,"#fentai.png", this.callback);
		fentai.right(zhui, this.rm);
		
		var jiajicheng = new LibButton(this, 10, TAG_LIB_JIAJICHENG,"#jiajicheng.png", this.callback);
		jiajicheng.right(fentai, this.rm);

	},
	moveLib:function(tag,width){
		width = 77;
		var begin = false;
		for(var i in this.libArr){
			var libTag = this.libArr[i];
			if(tag == libTag){
				begin = true;
			}
			if(begin){
				var lib = this.getChildByTag(libTag);
				if(lib != null){
					lib.runAction(cc.moveBy(0.5,cc.p(-width, 0)));
				}
			}
		}
	},
	callback:function(p){
		var pos = this.getPosition(); 
		var action = gg.flow.flow.action;
		switch(p.getTag()){
			case TAG_LIB_ZILAISHUI:
				ll.run.loadZilaishui(pos);
				break;
			case TAG_LIB_ZHENGLIUSHUI:
				ll.run.loadZhengliushui(pos);
				break;
			case TAG_LIB_DDG:
				ll.run.loadDidingguan(pos);
				break;
			case TAG_LIB_XISHUIZHI:
				ll.run.loadXishuizhi(pos);
				break;
			case TAG_LIB_IRON:
				ll.run.loadIron(pos);
				break;
			case TAG_LIB_BEAKER:
				ll.run.loadBeaker(pos);	
				break;
			case TAG_LIB_HCL:
				ll.run.loadHcl(pos);
				break;
			case TAG_LIB_YIYEGUAN:
				ll.run.loadYiyeguan(pos);
				break;
			case TAG_LIB_XIERQIU:
				ll.run.loadXierqiu(pos);
				break;
			case TAG_LIB_JIANYE:
				ll.run.loadJianye(pos);
				break;
			case TAG_LIB_ZHUIXINGPING:
				ll.run.loadZhuixingping(pos);
				break;
			case TAG_LIB_FENTAI:
				ll.run.loadFentai(pos);
				break;
			case TAG_LIB_JIAJICHENG:
				ll.run.loadJiajicheng(pos);
				break;
			case TAG_LIB_DROP:
				ll.run.loadDrop(pos);
				break;
			case TAG_LIB_POT:
				ll.run.loadPot(pos);
				break;
			case TAG_LIB_PH:
				ll.run.loadPH(pos);
				break;
			case TAG_LIB_AIR:
				ll.run.loadAir(pos);
				break;
			case TAG_LIB_SPOON:
				ll.run.loadSpoon(pos);
				break;
			case TAG_LIB_PAPER2:
				ll.run.loadPaper2(pos);
				break;
			default:
				break;
		}
		if(action == ACTION_NONE){
			this.moveLib(p.getTag(), p.width * p.getScale());
			p.removeFromParent(true);
		}
	},
	isOpen:function(){
		return this.openFlag; 
	},
	open:function(){
		if(this.openFlag || this.doing){
			return;
		}
		this.doing = true;
		var move = cc.moveBy(0.4, cc.p(-this.width,0));
		var func = cc.callFunc(function(){
			this.openFlag = true;
			this.doing = false;
			var tag = gg.flow.flow.tag;
			 if(tag instanceof Array){
				 if(TAG_LIB_MIN < tag[1]){
					 // 显示箭头
					 gg.flow.location();
				 }
			 }
		}, this);
		var seq = cc.sequence(move,func);
		this.runAction(seq);
	},
	close:function(){
		if(!this.openFlag || this.doing){
			return;
		}
		this.doing = true;
		var move = cc.moveBy(0.4, cc.p(this.width,0));
		var func = cc.callFunc(function(){
			this.openFlag = false;
			this.doing = false;
			var tag = gg.flow.flow.tag;
			if(tag instanceof Array){
				if(TAG_LIB_MIN < tag[1]){
//					// 隐藏箭头
//					ll.tip.arr.out();
					//箭头指向按钮
					ll.tip.arr.setPosition(gg.width-45,455);
				}
			}
		}, this);
		var seq = cc.sequence(move,func);
		this.runAction(seq);
	}
});
TAG_LIB_MIN = 30000;
TAG_LIB_SALT = 30001;
TAG_LIB_SPOON = 30002;
TAG_LIB_KETTLE = 30003;
TAG_LIB_PAPER = 30004;

TAG_LIB_FUNNEL = 30006;
TAG_LIB_ROD = 30007;

TAG_LIB_LAMP = 30009;
TAG_LIB_SHELF = 30010;
TAG_LIB_NET = 30011;
TAG_LIB_DROP = 30012;
TAG_LIB_CYLINDER = 30013;
TAG_LIB_POT = 30014;
TAG_LIB_PH = 30015;
TAG_LIB_AIR = 30016;
TAG_LIB_SPOON = 30017;
TAG_LIB_PAPER2 = 30018;
TAG_LIB_MATCH = 30019;
///////////////////////////////////////////////
TAG_LIB_ZILAISHUI=40001;
TAG_LIB_ZHENGLIUSHUI=40002;
TAG_LIB_DDG=40003;
TAG_LIB_IRON = 40004;
TAG_LIB_XISHUIZHI=40005;
TAG_LIB_BEAKER=40006;
TAG_LIB_HCL=40007;
TAG_LIB_YIYEGUAN=40008;
TAG_LIB_JIANYE=40009;
TAG_LIB_ZHUIXINGPING=40010;
TAG_LIB_FENTAI=40011;
TAG_LIB_JIAJICHENG=40012;
TAG_LIB_XIERQIU=40013;
libRelArr = [
             {tag:TAG_LIB_MIN, name:""},
             {tag:TAG_LIB_ZILAISHUI, name:"自来水"},
             {tag:TAG_LIB_ZHENGLIUSHUI, name:"蒸馏水"},
             {tag:TAG_LIB_IRON, name:"滴定管架"},
             {tag:TAG_LIB_DDG, name:"滴定管"},
             {tag:TAG_LIB_XISHUIZHI, name:"吸水纸"},
             {tag:TAG_LIB_BEAKER, name:"烧杯"},
             {tag:TAG_LIB_HCL, name:"盐酸"},
             {tag:TAG_LIB_YIYEGUAN, name:"移液管"},
             {tag:TAG_LIB_XIERQIU, name:"洗耳球"},
             {tag:TAG_LIB_JIANYE, name:"混合碱"},
             {tag:TAG_LIB_ZHUIXINGPING, name:"锥形瓶"},
             {tag:TAG_LIB_FENTAI, name:"酚酞"},
             {tag:TAG_LIB_JIAJICHENG, name:"甲基橙"}];